<template>
	<view>
		<!-- 顶部地图 -->
		<view class="maps" :style="{height:mapHeight}">
			<map id="map" @markertap="markertap" style="width: 100%;height: 100%;" :latitude="latitude"
				:longitude="longitude" :markers="covers" :show-location="true" :polyline="polyline"
				:polygons="polylist">
			</map>
		</view>
		<!-- 底部地址 -->
		<view class="addressInfo flex align-center justify-center" :style="{height:addressHeight}">
			<view class="addressInfo-box flex align-center justify-center flex-wrap">
				<view @click="selectStartAddress()" class="addressInfo-box-item flex align-center justify-between">
					<view class="addressInfo-box-item-l flex align-center">
						<view class="addressInfo-box-item-l-dian addressInfo-box-item-l-dian1"></view>
						从
						<view class="addressInfo-box-item-l-address">
							{{startAddress.address?startAddress.address:'选择位置'}}
						</view>
						出发
					</view>
					<view class="addressInfo-box-item-r">
						<u-icon name="arrow-right" color="#CCCCCC" size="28"></u-icon>
					</view>
				</view>
				<view @click="selectEndAddress()" class="addressInfo-box-item flex align-center justify-between">
					<view class="addressInfo-box-item-l flex align-center">
						<view class="addressInfo-box-item-l-dian"></view>
						<view class="addressInfo-box-item-l-name">
							{{endAddress.address?endAddress.address:'选择目的地'}}
						</view>
					</view>
					<view class="addressInfo-box-item-r">
						<u-icon name="arrow-right" color="#CCCCCC" size="28"></u-icon>
					</view>
				</view>
				<view class="flex align-center justify-center" v-if="startAddress.address">
					<view class="flex" style="color: #cccccc;" @click="showTimeSel()">
						{{timeIdName?timeIdName+'代驾':'小时代驾'}}
						<u-icon name="arrow-right" color="#CCCCCC" size="28"></u-icon>
					</view>
				</view>
				<view @click="payOrder()" v-if="startAddress.address && endAddress.address"
					class="addressInfo-box-item flex align-center justify-center"
					style="background-color: #346ef6;color: #ffffff;">
					立即下单
				</view>
				<view @click="payOrder()" v-else class="addressInfo-box-item flex align-center justify-center"
					style="background-color: #f5f8ff;">
					立即下单
				</view>
				<view @click="openmingxi()" v-if="startAddress.address && endAddress.address"
					class="addressInfo-box-txt flex align-center justify-center">
					查看明细<u-icon name="arrow-right" color="#CCCCCC" size="18" style="margin-left: 10rpx;"></u-icon>
				</view>
			</view>
		</view>
		<cover-view v-if="qxshow" class="flex align-center justify-center" @click="closeQrCode()"
			style="transition: opacity .5s;background: rgba(0, 0, 0, 0.2);width: 100%;height: 100vh;position: absolute;top: 0;left: 0;z-index: 9;">
			<cover-view class="" style="background: #FFFFFF;border-radius: 24rpx;width: 480rpx;">
				<cover-view class="padding text-center">
					<cover-view>扫我下单</cover-view>
					<cover-image @click="priveImgs(qrCodeImg)" :src="qrCodeImg"
						style="width: 400rpx;height: 400rpx;margin: 20rpx auto;border-radius: 24rpx;"></cover-image>
					<cover-view v-if="shifuInfo.riderStatus == 0" style="color: #32cd32;">师傅当前空闲中</cover-view>
					<cover-view v-if="shifuInfo.riderStatus == 1" style="color: #ff0000;">师傅当前忙碌中</cover-view>
					<cover-view style="margin-top: 10rpx;" @click="callPhone(shifuInfo.phone)"
						class="flex align-center justify-center">
						师傅电话：{{maskPhone(shifuInfo.phone)}}
						<cover-image src="../../static/my/ic_phone.png"
							style="width: 30rpx;height: 30rpx;"></cover-image>
					</cover-view>
					<cover-image @click="closeQrCode()" src="/static/image/gb.png"
						style="width: 50rpx;height: 50rpx;margin: 0 auto;margin-top: 40rpx;"></cover-image>
				</cover-view>
			</cover-view>
		</cover-view>
		<cover-view v-else></cover-view>

		<cover-view v-if="moneyShow" class="flex align-center justify-center" @click="moneyShow = false"
			style="background: rgba(0, 0, 0, 0.2);width: 100%;height: 100vh;position: absolute;top: 0;left: 0;z-index: 9;">
			<cover-view style="width: 520rpx;background: #FFFFFF;border-radius: 24rpx;position: relative;z-index: 99;">
				<cover-view class="text-lg text-bold text-center margin-top">价格明细</cover-view>
				<cover-view class="margin-tb" style="padding-left: 100rpx;">
					<cover-view class="margin-bottom-xs">总费用：￥{{basicPrice.allMoney}}</cover-view>
					<block v-if="!timeId">
						<cover-view class="margin-bottom-xs"
							v-if="basicPrice.distance">总公里数：{{basicPrice.distance}}km</cover-view>
						<cover-view class="margin-bottom-xs"
							v-if="basicPrice.kilometer">基础公里数：{{basicPrice.kilometer}}km</cover-view>
						<cover-view class="margin-bottom-xs"
							v-if="basicPrice.initMoney">基础起步价：￥{{basicPrice.initMoney}}</cover-view>
						<cover-view class="margin-bottom-xs"
							v-if="basicPrice.metre">超出部分公里数：{{basicPrice.metre}}km</cover-view>
						<cover-view class="margin-bottom-xs"
							v-if="basicPrice.unitOverMoney">超出部分每公里价格：￥{{basicPrice.unitOverMoney}}</cover-view>
						<cover-view class="margin-bottom-xs"
							v-if="basicPrice.otherMoney">超出部分收费总金额：￥{{basicPrice.otherMoney}}</cover-view>
						<cover-view class="margin-bottom-xs" v-if="basicPrice.isNight==1">当前是夜间时段 </cover-view>
						<cover-view class="margin-bottom-xs" v-if="basicPrice.isBeforeDawn==1">当前是凌晨时段 </cover-view>
						<cover-view class="margin-bottom-xs"
							v-if="basicPrice.durationAllMoney">预估总时长费：￥{{basicPrice.durationAllMoney}}</cover-view>
						<cover-view v-if="basicPrice.durationMoney">每分钟时长费：￥{{basicPrice.durationMoney}}</cover-view>
					</block>

				</cover-view>
				<cover-view class="margin-bottom flex align-center justify-center">
					<cover-image @click.stop="moneyShow = false" src="../../static/image/gb.png"
						style="width: 50rpx;height: 50rpx;"></cover-image>
				</cover-view>
			</cover-view>
		</cover-view>
		<cover-view v-else></cover-view>
		<!-- 选择时间段弹窗 -->
		<u-select v-model="showTime" @cancel="cancelTime" cancel-text="清除" label-name="timeNum" value-name="timeId"
			@confirm="confirmTime" :list="timeList"></u-select>

		<u-popup :show="isShowTipImgs" zIndex="99999999" mode="top">
			<view class="tipsmkf">
				申请麦克风权限，便于您使用该功能上传您的语音，
			</view>
		</u-popup>
	</view>
</template>

<script>
	// #ifdef H5
	var recorder; // 定义一个MediaRecorder对象
	var stream; //定义一个音频流的对象
	var chunks = []; // 定义一个用于存储音频数据片段的数组
	// #endif
	// 引入SDK核心类，地图组件
	import QQMapWX from '@/components/qqmap-wx-jssdk1.2/qqmap-wx-jssdk.js'
	import configdata from '../../common/config.js'
	export default {
		data() {
			return {
				//录音相关参数
				// #ifndef H5
				//H5不能录音
				RECORDER: uni.getRecorderManager(),
				// #endif
				isShowTipImgs: false,
				//播放语音相关参数
				AUDIO: uni.createInnerAudioContext(),
				playMsgid: null,
				VoiceTimer: null,
				contentUrl: '',
				recordLength: '',
				voicePaths: '',
				voicePath: '',
				blobData: '',
recordTimer: null,


				moneyType: 1,
				wxPayQr: '',
				wxPayshow: false,
				moneyShow: false,
				qxshow: false,
				mapHeight: 0,
				addressHeight: 0,
				latitude: '', //中心位置
				longitude: '', //
				covers: [], //地图标记点
				polyline: [], //区域
				polylist: [],
				key: '', //腾讯地图key
				startAddress: {
					lng: '',
					lat: '',
					address: '',
					province: '',
					city: '',
					county: ''
				}, //开始位置/我的位置
				endAddress: {
					lng: '',
					lat: '',
					address: '',
					province: '',
					city: '',
					county: ''
				},
				to: { // 目的地坐标
					latitude: '',
					longitude: '',
				},
				qqmapsdk: {}, // 腾讯地图小程序的SDK
				polylines: '',
				city: '',
				province: '',
				qrCodeImg: '',
				basicPrice: {}, //基础价格
				timeList: [],
				showTime: false,
				timeId: '',
				timeIdName: '',
				shifuInfoList: [], //师傅的位置
				shifuInfo: {},
				checkCertification: 0, //是否实名 0审核 1已实名 2已拒绝
				cashDeposit: 0, //缴纳保证金
				onLineFlag: 1, //1上线 2下线
				riderLine: 0,
				orderleng: 0,
				isVip: -1
			}
		},
		onHide() {
			console.log('离开卸载')
			this.voiceEnd()
			this.AUDIO.stop();
		},
		onLoad(e) {
			let that = this
			// #ifndef H5
			//录音开始事件
			that.RECORDER.onStart((e) => {
				console.log('监听开始录音' + e)
			})
			//录音结束事件
			that.RECORDER.onStop((e) => {
				console.log('监听结束录音' + e)
				that.recordEnd(e);
			})
			// #endif
			const sysInfo = uni.getSystemInfoSync()
			const windowHeight = sysInfo.windowHeight
			that.mapHeight = (windowHeight * 0.60).toFixed(0) + 'px'
			that.addressHeight = (windowHeight * 0.4).toFixed(0) + 'px'
			// that.getHoursList()
			that.key = uni.getStorageSync('mapKey')
			if (that.key) {
				// 实例化API核心类
				that.qqmapsdk = new QQMapWX({
					key: that.key // 自己申请的key值
				})
				that.getLocationAddress()
			}

		},
		onHide() {

		},
		onShow() {
			if (this.latitude && this.longitude) {
				this.getLocationAddressMap()
			}
			if (this.$queue.getData('token')) {
				this.$Request.getT('/app/indent/getRiderIndentList?page=1&limit=2&indentState=2').then(
					res => {
						if (res.code === 0) {
							if (res.data.records && res.data.records.length != 0) {
								this.StartMp()
							} else {
								uni.removeStorageSync('orderIndentId')
							}
						}
					});
				
				this.getVip()
				this.getUserInfo()
				this.getOrders()
			}

		},
		methods: {
			// 获取会员详情
			getVip() {
				this.$Request.getT("/app/UserVip/selectUserVip").then(res => {
					if (res.code == 0 && res.data) {
						this.isVip = res.data.isVip
					}
				});
			},
			StartMp() { //  开始录音
				let that = this
				// #ifdef APP
				// 在弹出选择弹框之前先判断一下是否获取了相册权限
				const sysInfo = uni.getSystemInfoSync()
				if (sysInfo.osName == 'ios') { //ios

				} else { //安卓
					var Manifest = plus.android.importClass("android.Manifest");
					var MainActivity = plus.android.runtimeMainActivity();
					let flag = MainActivity.checkSelfPermission(Manifest.permission.RECORD_AUDIO)
					console.log(flag); // 查看是否拥有相机权限 -1/0
					if (flag == -1) { //没有授权
						that.isShowTipImgs = true
						plus.android.requestPermissions(['android.permission.RECORD_AUDIO'], (success) => {
							that.isShowTipImgs = false
						}, (err) => {
							that.isShowTipImgs = false
						})
						return
					} else {
						that.isShowTipImgs = false
					}

				}
				// #endif
				// #ifdef H5
				if (stream) {
					stream.getTracks().forEach((track) => track.stop())
					stream = null
				}
				if (recorder) {
					recorder = null
				}
				that.recordLength = 0
				that.voicePaths = '';
				that.voicePath = '';
				that.startRecord()
				// #endif
				// #ifndef H5
				that.RECORDER.start({
					format: "mp3"
				}); //录音开始,
				that.recordBegin()
				// #endif
			},
			//开始录音
			startRecord: async function() {
				let _this = this
				// 获取麦克风音频数据流
				stream = await navigator.mediaDevices.getUserMedia({
					audio: true
				})
				// 初始化MediaRecorder对象
				recorder = new MediaRecorder(stream);
				// console.log('asdsad___' + recorder)
				// alert('asdsad___' + recorder)
				// 将 stream 转成 blob 来存放
				recorder.ondataavailable = (blobEvent) => {
					chunks.push(blobEvent.data);
				}
				// 停止时生成预览的 blob url
				recorder.onstop = () => {
					const blob = new Blob(chunks, {
						type: 'audio/mp3'
					})
					_this.voicePaths = blob;
					_this.blobData = blob;

				}
				recorder.start();
				_this.recordBegin()
			},
			//录音开始UI效果
			recordBegin() {
				this.recordLength = 0;
				this.recordTimer = setInterval(() => {
					this.recordLength++;
				}, 1000)
			},
			// 结束录音
			voiceEnd() {
				//原生录音停止
				// #ifdef H5
				//停止录音
				if (recorder.state != "inactive") {
					recorder.stop();
				}
				//把音频流也停止掉
				stream.getTracks().forEach((track) => track.stop())
				this.uplodMp3(this.voicePaths);
				// #endif

				// #ifndef H5
				this.RECORDER.stop(); //录音结束
				// #endif

			},
			//录音结束(回调文件)
			recordEnd(e) {
				clearInterval(this.recordTimer);
				// uni.showLoading({
				// 	title: '发送中'
				// });
				let indentId = uni.getStorageSync('orderIndentId')
				if (indentId && e.tempFilePath&&this.recordLength>3) {
					uni.uploadFile({ // 上传接口
						url: this.config("APIHOST1") + '/app/indent/uploadIndent?indentId=' + indentId, //真实的接口地址
						filePath: e.tempFilePath,
						name: 'file',
						success: (uploadFileRes) => {
							console.log('------------' + uploadFileRes.data)
							uni.hideLoading();
							let url = JSON.parse(uploadFileRes.data)
							if (url.code == 0) {
								console.log('上传成功')
							} else {
								uni.showToast({
									title: url.msg,
									icon: 'none'
								})
							}

						},
						fail: (err) => {
							console.log('err' + err)
						}
					});
				}

			},
			//上传mp3格式的音频
			uplodMp3(recordPath) {
				let _this = this;
				clearInterval(_this.recordTimer);
				let indentId = uni.getStorageSync('orderIndentId')
				if (indentId && _this.blobData&&_this.recordLength>3) {
					uni.uploadFile({ // 上传接口
						url: _this.config("APIHOST1") + '/app/indent/uploadIndent?indentId=' + indentId, //真实的接口地址
						file: _this.blobData,
						name: 'file',
						success: (uploadFileRes) => {
							uni.hideLoading();
							let url = JSON.parse(uploadFileRes.data)
							if (url.code == 0) {} else {
								uni.showToast({
									title: url.msg,
									icon: 'none'
								})
							}
						}
					});
				}
			},
			config: function(name) {
				var info = null;
				if (name) {
					var name2 = name.split("."); //字符分割
					if (name2.length > 1) {
						info = configdata[name2[0]][name2[1]] || null;
					} else {
						info = configdata[name] || null;
					}
					if (info == null) {
						let web_config = cache.get("web_config");
						if (web_config) {
							if (name2.length > 1) {
								info = web_config[name2[0]][name2[1]] || null;
							} else {
								info = web_config[name] || null;
							}
						}
					}
				}
				return info;
			},


			maskPhone(phone) {
				return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
			},
			callPhone(num) {
				uni.makePhoneCall({
					phoneNumber: num
				})
			},
			getquyuList() {
				let data = {
					city: this.city,
					// district: this.district,
					province: this.province,
				}
				this.$Request.get("/app/banArea/getBanAreaList", data).then(res => {
					if (res.code == 0) {
						let arr = []
						if (res.data.records && res.data.records.length > 0) {
							res.data.records.forEach((item, index) => {
								let dataList = [];
								item.points.forEach((ite, ind) => {
									dataList.push({
										latitude: ite.lat,
										longitude: ite.lng
									})
								})
								let ps = {
									points: dataList,
									strokeColor: "#0186FF",
									strokeWidth: 3,
									fillOpacity: 0.4,
								};
								arr.push(ps)

							});

							this.polylist = arr
						}

					}
				});
			},
			showTimeSel() {
				let data = {
					lat: this.startAddress.lat,
					lng: this.startAddress.lng
				}
				this.$Request.getT('/app/Login/selectCity', data).then(res => {
					if (res.code === 0) {
						this.getHoursList(res.data.city);
					}
				});
			},
			cancelTime() {
				this.timeId = ''
				this.timeIdName = ''
				this.showTime = false
				if (this.startAddress.address && this.endAddress.address) {
					this.orderPay()
				}
			},
			confirmTime(e) {
				this.timeId = e[0].value
				this.timeIdName = e[0].label
				if (this.startAddress.address && this.endAddress.address) {
					this.orderPay()
				}
				console.log(e[0], '444444444444')
			},
			getHoursList(city) {
				this.$Request.get('/app/packageTime/getPackageTimeList?cityName=' + city).then(res => {
					if (res.code == 0) {
						res.data.records.map(item => {
							// item.timeNum = item.timeNum + '小时'
							if (item.timeNum < 1) {
								item.timeNum = (item.timeNum * 60) + '分钟'
							} else {
								item.timeNum = item.timeNum + '小时'
							}
						})
						this.timeList = res.data.records
						this.showTime = true
					}
				})
			},
			// 获取个人信息
			getUserInfo() {
				this.$Request.getT("/app/userinfo/findUserInfoById").then(res => {
					if (res.code == 0) {
						this.$nextTick(function() {
							this.checkCertification = res.data.checkCertification
							this.cashDeposit = res.data.cashDeposit
							this.onLineFlag = res.data.onLineFlag
							this.riderLine = res.data.riderLine
						})
					} else {
						this.$queue.logout();
						uni.showModal({
							showCancel: false,
							title: '登录失败',
							content: res.msg,
						});
					}
				});
			},
			getOrders() {
				this.$Request.getT('/app/indent/getRiderIndentList', {
					page: 1,
					limit: 10,
					indentState: 1
				}).then(res => {
					if (res.code == 0) {
						this.orderleng = res.data.total
					}
				});
			},
			//下单
			payOrder() {

				if (this.onLineFlag == 1) {
					if (this.checkCertification == 1) {
						this.$Request.getT('/app/common/type/261').then(res => {
							if (res.code === 0) {
								let baozhengjin = res.data.value;
								this.getOrders()
								let DepositSwitch = uni.getStorageSync('DepositSwitch')
								if (DepositSwitch == '是') {
									if ((Number(this.cashDeposit) < Number(baozhengjin))) {
										uni.showModal({
											title: '提示',
											content: '保证金不足，请先缴纳保证金后再接单',
											success: function(res) {
												if (res.confirm) {
													console.log('用户点击确定');
													uni.navigateTo({
														url: '/my/wallet/baozhengjin'
													})
												} else if (res.cancel) {
													console.log('用户点击取消');
												}
											}
										});
										return
									}
								}
								let VipSwitch = uni.getStorageSync('VipSwitch')
								if (VipSwitch == '是') {
									if (this.isVip != 1) {
										uni.showModal({
											title: '提示',
											content: '接单需要先开通会员',
											success: function(res) {
												if (res.confirm) {
													console.log('用户点击确定');
													uni.navigateTo({
														url: '/my/vip/vip'
													})
												} else if (res.cancel) {
													console.log('用户点击取消');
												}
											}
										});
										return
									}
								}
								if (this.orderleng == 0) {

									// let that = this
									if (!this.startAddress.address) {
										uni.showToast({
											title: '请选择出发位置',
											icon: 'none'
										})
										return
									}
									if (!this.endAddress.address) {
										uni.showToast({
											title: '请选择目的地',
											icon: 'none'
										})
										return
									}
									let data = {
										addType: 2, //下单类型 1:用户下单 2:司机下单
										indentType: 1,
										//出发位置
										shipAddress: this.startAddress.address,
										shipAddressLongitude: this.startAddress.lng,
										shipAddressLatitude: this.startAddress.lat,
										shipDistrict: this.startAddress.county,
										shipProvince: this.startAddress.province,
										shipCity: this.startAddress.city,
										//目的地位置
										deliveryAddress: this.endAddress.address,
										deliveryAddressLongitude: this.endAddress.lng,
										deliveryAddressLatitude: this.endAddress.lat,
										deliveryDistrict: this.endAddress.county,
										deliveryProvince: this.endAddress.province,
										deliveryCity: this.endAddress.city,
										//
										remarks: '',
										couponId: '',
										itemCodeFlag: 1,
										payUser: 0,
										type: '',
										moneyType: this.moneyType
									}
									if (this.timeId) {
										data.moneyType = 1
										data.timeId = this.timeId
									} else {
										data.moneyType = 2
									}
									this.$Request.postJson('/app/indent/addIndent', data).then(res => {
										if (res.code == 0) {
											uni.showToast({
												title: '下单成功'
											})
											let that = this
											that.getOrders()
											uni.switchTab({
												url: '/pages/order/order',
												success() {
													that.endAddress = {
														lng: '',
														lat: '',
														address: '',
														province: '',
														city: '',
														county: ''
													}
												}
											})
										} else {
											uni.showToast({
												title: res.msg,
												icon: 'none'
											})
										}
									})
								} else {
									uni.showModal({
										title: '提示',
										content: '师傅已有待服务订单，请完成后再下单',
										success: function(res) {
											if (res.confirm) {
												console.log('用户点击确定');
												let that = this
												uni.switchTab({
													url: '/pages/order/order',
													success() {
														that.endAddress = {
															lng: '',
															lat: '',
															address: '',
															province: '',
															city: '',
															county: ''
														}
													}
												})
											} else if (res.cancel) {
												console.log('用户点击取消');

											}
										}
									});
								}
							}
						});
					} else if (this.checkCertification == 0) {
						uni.showToast({
							title: '实名认证审核中，请稍等...',
							icon: 'none'
						})
						return
					} else if (this.checkCertification == '' || this.checkCertification == null) {
						uni.showModal({
							title: '提示',
							content: '请先实名认证后再接单',
							success: function(res) {
								if (res.confirm) {
									console.log('用户点击确定');
									uni.navigateTo({
										url: '/my/renzheng/index'
									})
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						});
						return;
					}
				} else {
					let that = this
					uni.showModal({
						title: '提示',
						content: '当前下线中,是否现在上线?',
						complete: function(ret) {
							if (ret.confirm) {
								console.log('用户点击确定');
								uni.showLoading({
									title: '修改中...',
								})
								that.$Request.postT("/app/user/updateLine").then(res => {
									// that.$Request.postJson("/app/user/updateUser", {
									// 	onLineFlag: 1
									// }).then(res => {
									uni.hideLoading();
									if (res.code === 0) {
										that.getUserInfo();
									} else {
										that.$queue.showToast(res.msg)
									}
								});
							} else if (ret.cancel) {
								console.log('用户点击取消');
							}
						}
					});
					return;
				}

			},
			openmingxi() { //查看价格明细
				this.moneyShow = true
			},
			closeQrCode() {
				this.qxshow = false
				this.qrCodeImg = false
			},
			//预览图片
			priveImgs(img) {
				uni.previewImage({
					urls: [img]
				})
			},
			//获取点击师傅的二维码
			markertap(e) {
				let that = this
				let indexs = this.shifuInfoList.findIndex(item => item.userId == e.markerId)
				if (indexs != -1) {
					console.log(indexs, '555555555')
					let userId = e.markerId
					uni.downloadFile({
						url: configdata.APIHOST + '/app/invite/riderQr?userId=' + userId,
						success(res) {
							that.qrCodeImg = res.tempFilePath
							that.shifuInfo = that.shifuInfoList[indexs]
							that.qxshow = true

						}
					})
				}

			},
			//获取附近的师傅信息
			getLocationAddressMap() {
				if (!uni.getStorageSync('token')) {
					return
				}
				let data = {
					lat: this.latitude,
					lng: this.longitude,
					city: this.city
				}
				this.$Request.getT('/app/user/getRiderCount', data).then(res => {
					if (res.code == 0) {

						if (res.data && res.data.length > 0) {
							this.shifuInfoList = res.data
							res.data.map((item, index) => {
								let obj = {
									id: item.userId,
									latitude: item.lat,
									longitude: item.lng,
									iconPath: '../../static/image/shifuAvatar.png',
									width: 32,
									height: 32,
									callout: {
										content: item.userName ? item.userName : '',
										color: '#333333', //文字颜色
										fontSize: 10, //文本大小
										padding: 10, //附近留白
										borderRadius: 6, //边框圆角
										bgColor: item.riderStatus == 0 ? '#32cd32' : '#ff0000', //背景颜色
										display: 'ALWAYS', //常显
									}
								}
								this.covers.push(obj)
							})
						}

					}
				})
			},
			//绘制导航路径
			routePlanning() {
				let that = this
				that.qqmapsdk.direction({
					mode: 'driving', // 驾车
					from: { // 起始位置(当前位置)坐标
						latitude: that.latitude,
						longitude: that.longitude
					},
					to: that.to, // 目的地位置坐标
					success(res) {
						// console.log(res, '=======')
						var coors = JSON.parse(that.polylines)
						// console.log(coors,'11111111111111')
						// var coors = res.result.routes[0].polyline
						// console.log(coors2,'11111111111111')
						var pl = [] // 点串数组
						// 坐标解压(返回的点串坐标，通过前向差分进行压缩)
						var kr = 1000000
						for (var i = 2; i < coors.length; i++) {
							coors[i] = Number(coors[i - 2]) + Number(coors[i]) / kr
						}
						// 将解压后的坐标放入点串数组pl中
						for (var i = 0; i < coors.length; i += 2) {
							pl.push({
								latitude: coors[i],
								longitude: coors[i + 1]
							})
						}
						// 设置polyline属性，将路线显示出来，将解压坐标第一个数据作为起点
						that.polyline = [{
							points: pl,
							color: '#346EF6',
							width: 4
						}]
					}
				})
			},
			selectEndAddressTo(longitude, latitude, name) {
				this.$Request.getT('/app/Login/selectCity?lat=' + latitude + '&lng=' + longitude).then(res => {
					if (res.code === 0) {
						this.endAddress.lng = longitude
						this.endAddress.lat = latitude
						this.endAddress.address = name
						this.endAddress.province = res.data.province
						this.endAddress.city = res.data.city ? res.data.city : res.data.province
						this.endAddress.county = res.data.district
						this.to.latitude = latitude
						this.to.longitude = longitude
						this.covers = [{
							id: 1,
							latitude: this.startAddress.lat,
							longitude: this.startAddress.lng,
							iconPath: '../../static/image/qi.png',
							width: 32,
							height: 44,
							callout: { //自定义标记点上方的气泡窗口 点击有效
								content: this.startAddress.address, //文本
								color: '#333333', //文字颜色
								fontSize: 10, //文本大小
								padding: 10, //附近留白
								borderRadius: 6, //边框圆角
								bgColor: '#FFFFFF', //背景颜色
								display: 'ALWAYS', //常显
							},
						}, {
							id: 2,
							latitude: latitude,
							longitude: longitude,
							iconPath: '../../static/image/zd.png',
							width: 32,
							height: 44,
							callout: { //自定义标记点上方的气泡窗口 点击有效
								content: name, //文本
								color: '#333333', //文字颜色
								fontSize: 10, //文本大小
								padding: 10, //附近留白
								borderRadius: 6, //边框圆角
								bgColor: '#FFFFFF', //背景颜色
								display: 'ALWAYS', //常显
							},
						}]
						if (this.startAddress && this.startAddress.lng && this.endAddress && this.endAddress.lng) {
							this.orderPay()
						}
					}
				});
			},
			orderPay() {
				let data = {
					goLng: this.startAddress.lng,
					goLat: this.startAddress.lat,
					toLng: this.endAddress.lng,
					toLat: this.endAddress.lat,
					redPacketId: '',
					// goCity: this.startAddress.city, //出发市
					goCity: this.startAddress.city, //出发市
					goDistrict: this.startAddress.county, //区

					toCity: this.endAddress.city, //目的市
				}
				if (this.timeId) {
					data.moneyType = 1
					data.timeId = this.timeId
				} else {
					data.moneyType = 2
				}
				this.$Request.getT('/app/indent/basicsMoney', data).then(res => {
					if (res.code == 0) {

						this.basicPrice = res.data
						this.polylines = res.data.polyline
						this.routePlanning()
						// this.gethaveOrder()
						// this.popupshow = false
						// this.ordershow = true
						// this.routePlanning()
						// this.getyouhui() //获取优惠劵

					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				});
			},
			//选择结束位置
			selectEndAddress() {
				if (uni.getStorageSync('token')) {
					let that = this
					uni.chooseLocation({
						success(res) {
							that.selectEndAddressTo(res.longitude, res.latitude, res.name)
							console.log(res, '111111')
						}
					})
				} else {
					uni.navigateTo({
						url: '/pages/login/login'
					})
				}

			},
			//选择开始位置
			selectStartAddress() {
				if (uni.getStorageSync('token')) {
					let that = this
					uni.chooseLocation({
						success(res) {
							that.selectCity(res.longitude, res.latitude, res.name)
							console.log(res, '111111')
						}
					})
				} else {
					uni.navigateTo({
						url: '/pages/login/login'
					})
				}

			},
			//获取定位
			getLocationAddress() {
				let that = this
				uni.getLocation({
					// #ifdef APP
					type: 'wgs84',
					// #endif
					// #ifndef APP
					type: 'gcj02', //wgs84  gcj02
					// #endif
					geocode: true, //设置该参数为true可直接获取经纬度及城市信息
					success: function(res) {
						console.log(res, '地理位置')
						that.latitude = res.latitude
						that.longitude = res.longitude
						that.selectCity(that.longitude, that.latitude);

					},
					fail: function() {
						console.log('获取地址失败')
						uni.startLocationUpdate({
							type: 'gcj02', //gcj02  wgs84
							isHighAccuracy: true, //开启高精度定位(！！！必需)
							geocode: true,
							success: res => {
								uni.onLocationChange(function(res2) {
									that.latitude = res2.latitude
									that.longitude = res2.longitude
									that.selectCity(that.longitude, that.latitude)
								});
							},
							fail: err => {
								// clearInterval(this.ordertimer)
								console.error('开启小程序接收位置消息失败：', err)
							},
							complete: msg => {
								// clearInterval(this.ordertimer)
								console.log('调用开启小程序接收位置消息 API 完成')
							}
						});
					}
				})
			},
			//设置地图标记
			selectCity(longitude, latitude, name) {
				this.$Request.getT('/app/Login/selectCity?lat=' + latitude + '&lng=' + longitude).then(res => {
					if (res.code == 0) {
						this.startAddress.city = res.data.city ? res.data.city : res.data.province
						this.startAddress.county = res.data.district
						this.startAddress.province = res.data.province
						this.startAddress.lng = longitude
						this.startAddress.lat = latitude
						if (name) {
							this.startAddress.address = name
						} else {
							this.startAddress.address = res.data.address
						}
						this.city = this.startAddress.city
						this.province = this.startAddress.province
						this.getquyuList()
						this.covers = [{
							id: 1,
							latitude: latitude,
							longitude: longitude,
							iconPath: '../../static/image/qi.png',
							width: 32,
							height: 44,
							callout: { //自定义标记点上方的气泡窗口 点击有效
								content: this.startAddress.address, //文本
								color: '#333333', //文字颜色
								fontSize: 10, //文本大小
								padding: 10, //附近留白
								borderRadius: 6, //边框圆角
								bgColor: '#FFFFFF', //背景颜色
								display: 'ALWAYS', //常显
							},
						}]
						this.getLocationAddressMap()
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})
			},

		}
	}
</script>

<style lang="scss">
	page {
		background: #F5F5F5;
	}

	.maps {
		width: 100%;

	}

	.addressInfo {
		width: 100%;
		padding: 20rpx 0;

		.addressInfo-box {
			width: 686rpx;
			height: 100%;
			background-color: #ffffff;
			border-radius: 36rpx;
			padding: 20rpx;
		}

		.addressInfo-box-item:nth-of-type(1) {
			background-color: #f5f8ff !important;
		}

		.addressInfo-box-item {
			width: 100%;
			background-color: #F5F5F5;
			border-radius: 18rpx;
			color: #303133;
			font-weight: 500;
			font-size: 32rpx;
			line-height: 100rpx;
			padding: 0 20rpx;
		}



		.addressInfo-box-item-l-dian {
			width: 18rpx;
			height: 18rpx;
			background-color: #FBAC04;
			border-radius: 50%;
			margin-right: 30rpx;
		}

		.addressInfo-box-item-l-dian1 {
			background-color: #1FC657 !important;
		}

		.addressInfo-box-item-l-address {
			max-width: 400rpx;
			color: #346ef6;

			overflow: hidden;
			white-space: nowrap;
			text-overflow: ellipsis;
			-o-text-overflow: ellipsis;
		}

		.addressInfo-box-item-l-name {
			width: 500rpx;
			overflow: hidden;
			white-space: nowrap;
			text-overflow: ellipsis;
			-o-text-overflow: ellipsis;
		}

		.addressInfo-box-txt {
			width: 100%;
			font-size: 24rpx;
			color: #999999;
		}
	}
</style>